using  GoodDotNet.Core.Entity;
using  GoodDotNet.Core.IRepository;
using GoodDotNet.Core.Repository.BASE;
using GoodDotNet.Core.Data;
using Microsoft.EntityFrameworkCore;
using GoodDotNet.Core.Model;

namespace GoodDotNet.Core.Repository
{
  
  /**
   *
   * @author 大钊
   * @since 2023/9/17 10:42:46
   */
   public class  UserLogRepository : BaseRepository< UserLog>, UserLogIRepository
    {
        public  UserLogRepository(MyDbContext context) : base(context)
        {
        }
    
		
		
		 
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		/// @author 大钊
		/// @since 2023/9/17 10:42:46
		public List<UserLogGetPageDataModel> GetPage( UserLogGetPageParModel pars ){
		   var query = from user_log in this.context.UserLog
		    join user in this.context.User on user_log.UserId equals user.Id into UserLogUser from user in UserLogUser .DefaultIfEmpty()
		    
			orderby user_log.InsertTime    descending
		    select new UserLogGetPageDataModel
		   	{
		   		
				Content=user_log.Content,
				Ip=user_log.Ip,
				Event=user_log.Event,
				InsertTime=user_log.InsertTime,
				UserEmail=user.Email,
				UserGrade=user.Grade,
				UserNickname=user.Nickname,
				UserVipExpired=user.VipExpired
		   	};
		    return query.Skip((pars.PageIndex - 1) * pars.PageSize)
		    .Take(pars.PageSize)
		    .ToList();
		}
		
		


		
		
		 
		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		/// @author 大钊
		/// @since 2023/9/17 10:42:46
		public List<UserLogGetPageUserDataModel> GetPageUser( UserLogGetPageUserParModel pars ){
		   var query = from user_log in this.context.UserLog
		    join user in this.context.User on user_log.UserId equals user.Id into UserLogUser from user in UserLogUser .DefaultIfEmpty()
		    where user_log.UserId==pars.UserId
			orderby user_log.InsertTime    descending
		    select new UserLogGetPageUserDataModel
		   	{
		   		
				Content=user_log.Content,
				Ip=user_log.Ip,
				Event=user_log.Event,
				InsertTime=user_log.InsertTime,
				UserEmail=user.Email,
				UserGrade=user.Grade,
				UserNickname=user.Nickname,
				UserVipExpired=user.VipExpired
		   	};
		    return query.Skip((pars.PageIndex - 1) * pars.PageSize)
		    .Take(pars.PageSize)
		    .ToList();
		}
		
		

}
 }
